﻿@model BrnMall.Web.StoreAdmin.Models.StaffListModel
@using BrnMall.Manager.Domain.AddressBook

@section header{
    <title>订单列表-订单管理</title>
    <link type="text/css" rel="stylesheet" href="/admin_store/css/site.css"/>
    <link type="text/css" rel="stylesheet" href="/components/jbox/Skins/Default/jbox.css"/>
    <link href="/components/layui/layui.css" rel="stylesheet" media="all">
    <script type="text/javascript" src="/admin_store/scripts/jquery.js"></script>
    <script type="text/javascript" src="/admin_store/scripts/showlist.js"></script>
    <script type="text/javascript" src="/components/jbox/jquery.jBox-2.3.min.js"></script>
    <script src="/components/layer/layer.js"></script>
    <script src="~/admin_store/scripts/staff/staff.js"></script>
    <style type="text/css">
        .logo {float: left;margin-right: 5px;width: 60px;height: 60px}
        .list-header-mid-rgt {display: flex;flex-direction: row;justify-content: space-between;align-items: center}
        .list-header-btm {display: flex;flex-direction: row;justify-content: flex-start;align-items: center;margin-top: 5px}
        .list-header-btm-ipt {height: 30px;width: 200px;padding-left: 5px;outline: 0}
        .list-btn {height: 36px;width: 80px;display: flex;flex-direction: row;justify-content: center;align-items: center;background-color: #FF7B28;color: #fff;border-top-right-radius: 5px;border-bottom-right-radius: 5px}
    </style>
    <script>
        $(function() {
            loadBtn();
        })
        function loadBtn() {
            //显示头像
            $(".logo").each(function () {
                var avater = formatAvater($(this).attr("data-src"));
                $(this).attr("src", avater);
            })
            $(".ai-state").click(function () {
                setAiState($(this))
            })
            $(".boss-state").click(function () {
                setBossState($(this))
            })
        }
        

        function setAiState(obj) {
            var isChecked = obj.is(":checked");
            var data_id = obj.attr("data-id");
            var url = obj.data('url');

            $.jBox.tip("正在设置...", 'loading');

            $.get(url + '&state=' + (isChecked ? 1 : 0) + '&t=' + new Date(), function (data, textStatus) {
                if (data != "0") {
                    $.jBox.tip('设置成功！', 'success');

                } else {
                    $.jBox.error('设置失败', '设置失败');
                }
            });
        }

        function setBossState(obj) {
            var isChecked = obj.is(":checked");
            var data_id = obj.attr("data-id");
            var url = obj.data('url');

            $.jBox.tip("正在设置...", 'loading');

            $.get(url + '&state=' + (isChecked ? 1 : 0) + '&t=' + new Date(), function (data, textStatus) {
                if (data != "0") {
                    $.jBox.tip('设置成功！', 'success');

                } else {
                    $.jBox.error('设置失败', '设置失败');
                }
            });
        }

        //生成名片
        function mackCode(staffId) {
            $.get("@Url.Action("MackQrCode", "staff")&t=" + new Date(), function (data) {
                if (data.Code != 0) {
                    $.jBox.tip(data.Message);
                }
                console.log(data.Data);
            })
        }
    </script>
}

@section body{
    <h1 class="rightH1">
        微信小程序 &gt; 微街客 &gt; <span class="rightH1-cur">员工授权</span>
        <div class="clear"></div>
    </h1>
    @using (Html.BeginForm("authorization", "staff"))
    {
        <div class="container">
            
            <div class="container-rgt">
                <div class="content-list">
                    <div class="list-header">
                        <div class="list-header-tp">
                            <div class="list-header-tp-lft">
                                深圳企动网络有限公司（@Model.PageModel.TotalCount 人）
                            </div>                           
                        </div>                        
                        <div class="list-header-btm">
                            @Html.TextBox("NickName", Model.staffName, new { @class = "list-header-btm-ipt" })
                            <div class="list-btn">
                                <input id="SearchOrder" name="SearchOrder" type="image" class="searchBut submit" src="/admin_store/images/s.jpg" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="dataList">
            <table width="100%">
                <thead>
                    <tr>
                        <th style="width:3%;" align="center"><input type="checkbox" id="allSelect" /></th>
                        <th align="left">头像</th>
                        <th width="100" align="left">姓名</th>
                        <th width="140">职位</th>
                        <th width="80" align="left">部门</th>
                        <th width="100" align="left">手机</th>
                        <th width="100" align="left">AI销售和名片</th>
                        <th width="80" align="left">boss销售</th>
                        <th width="96" align="left">管理操作</th>
                    </tr>
                </thead>
                <tbody>

                    @foreach (Staff row in Model.staffList)
                    {
                        <tr data-id="@row.Id">
                            <td align="center"><input type="checkbox" value="@row.Id" selectItem="true" name="pidList" /></td>
                            <td>
                                <img class="logo" data-src="@row.Avater" />
                            </td>
                            <td>@row.Name</td>
                            <td>@row.Position</td>
                            <td>@row.Department</td>
                            <td>@row.Mobile</td>
                            <td style="text-align:center">
                                @if (row.AiState == 1)
                                {
                                        <input type="checkbox" class="SetStaffState ai-state" data-id="ai_@row.Id" mode="0"  data-url="@Url.Action("SetStaffState", "Staff",new { staffid = row.Id,mode=0 })" checked="checked" name="close" lay-skin="switch" lay-text="ON|OFF">
                                }
                                else
                                {
                                        <input type="checkbox" class="SetStaffState ai-state" data-id="@row.Id"  mode="0"  data-url="@Url.Action("SetStaffState", "Staff",new { staffid = row.Id,mode=0 })" name="close" lay-skin="switch" lay-text="ON|OFF">
                                }

                            </td>
                            <td style="text-align:center">
                                @if (row.BossState == 1)
                                {
                                        <input type="checkbox" class="SetStaffState boss-state" id="boss_@row.Id"  mode="1" data-url="@Url.Action("SetStaffState", "Staff", new { staffid = row.Id, mode = 1 })" checked="checked" name="close" lay-skin="switch" lay-text="ON|OFF">
                                }
                                else
                                {
                                        <input type="checkbox" class="SetStaffState boss-state" id="boss_@row.Id"  mode="1"  data-url="@Url.Action("SetStaffState", "Staff", new { staffid = row.Id, mode = 1 })" name="close" lay-skin="switch" lay-text="ON|OFF">
                                }

                            </td>
                            <td>
                                <a href="javascript:" class="btn-mack" onclick="mackCode(@row.Id)">生成名片</a>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
        <div class="dataListEdit">
            <div class="page">
                @Html.StoreAdminPager(Model.PageModel)
            </div>
        </div>
        <script>
            //生成明信片
            function mackCode(id) {
                var url = '@Url.Action("MackQrCode")'
                $.post(url, { staffId: id }, function (data) {
                    data = JSON.parse(data);
                    if (data.Code != 0) {
                        $.jBox.tip(data.Message);
                        return;
                    } else {
                        var imgUrl = data.Data;
                        console.log(imgUrl);
                        layer.open({
                            type: 1,
                            title: false,
                            closeBtn: 0,
                            area: ['429px', '400px'],
                            skin: 'layui-layer-nobg', //没有背景色
                            shadeClose: true,
                            content: '<img src="'+imgUrl+'" style="height:100%" />'
                        });
                    }
                    
                });
                
            }
        </script>
    }
}